<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="common/include :: header('新增结算单')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-contract-add" enctype="multipart/form-data">
        <input type="hidden" name="appendix" id="contractPath">
        <input type="hidden" name="bpmnInfoId" th:value="${bpmnInfoId}">
        <input type="hidden" name="director" th:value="${director}">
        <div class="form-group">
            <label class="col-sm-3 control-label">客户：</label>
            <div class="col-sm-8">
                <select name="customerId" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="customer : ${customers}" th:text="${customer.customerName}" th:value="${customer.id}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同名称：</label>
            <div class="col-sm-8">
                <input name="contractName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同编码：</label>
            <div class="col-sm-8">
                <input name="contractCode" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同金额：</label>
            <div class="col-sm-8">
                <input name="amounts" class="form-control" type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开始日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="startDate" class="form-control inputTime" placeholder="年/月/日" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">结束日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="endDate" class="form-control inputTime" placeholder="年/月/日" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">电子附件</label>
            <div id="uploadBtn" class="col-sm-8 fileinput fileinput-new" data-provides="fileinput">
        <span class="btn btn-outline-secondary btn-file">
            <input type="file" name="file"  id="bpmnInfoinition" multiple>
        </span>
                <span class="fileinput-filename"></span>
                <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
            </div>
        </div>
    </form>
</div>
<th:block th:include="common/include :: footer" />
<th:block th:include="common/include :: datetimepicker" />
<script th:inline="javascript">
    var prefix = ctx + "/business/contract";
    $("#form-contract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        $.modal.confirm("新增会立即发起合同审核，确定要新增吗？",function () {
            if ($.validate.form()) {
                var file = $('#bpmnInfoinition')[0].files[0];
                if (!file) {
                    $.modal.alert("请上传合同电子附件!");
                    return;
                }
                var formData = new FormData();
                formData.append("file",file);
                $.ajax({
                    url: prefix + '/uploadFileMinio',
                    type:"POST",
                    data:formData,
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $.operate.ajaxSuccess(result);
                            $("#contractPath").val(result.data);
                            $.operate.save(prefix + "/add", $('#form-contract-add').serialize());
                        }else {
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            }
        });
    }

    $(".inputTime").datetimepicker({
        format: "yyyy-mm-dd hh:ii",
        autoclose: true
    });
</script>
</body>
</html>